package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Sebas
 */
@Entity
@Table(name = "actor")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Actor.findAll", query = "SELECT a FROM Actor a"),
    @NamedQuery(name = "Actor.findByIdActor", query = "SELECT a FROM Actor a WHERE a.idActor = :idActor"),
    @NamedQuery(name = "Actor.findByActBirthdate", query = "SELECT a FROM Actor a WHERE a.actBirthdate = :actBirthdate"),
    @NamedQuery(name = "Actor.findByNameAndLastname", query = "SELECT a FROM Actor a WHERE a.actName = :actName OR a.actLastname = :actLastname")})
public class Actor implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id_actor")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer idActor;
    @Basic(optional = false)
    @Lob
    @Column(name = "act_name")
    private String actName;
    @Basic(optional = false)
    @Lob
    @Column(name = "act_lastname")
    private String actLastname;
    @Basic(optional = false)
    @Lob
    @Column(name = "act_picture")
    private String actPicture;
    @Basic(optional = false)
    @Column(name = "act_birthdate")
    @Temporal(TemporalType.DATE)
    private Date actBirthdate;
    @Basic(optional = false)
    @Lob
    @Column(name = "act_birthplace")
    private String actBirthplace;
    @JoinTable(name = "actor_has_movie", joinColumns = {
        @JoinColumn(name = "actor_id_actor", referencedColumnName = "id_actor")}, inverseJoinColumns = {
        @JoinColumn(name = "movie_id_movie", referencedColumnName = "id_movie")})
    @ManyToMany
    private Collection<Movie> movieCollection;

    public Actor() {
    }

    public Actor(Integer idActor) {
        this.idActor = idActor;
    }

    public Actor(Integer idActor, String actName, String actLastname, String actPicture, Date actBirthdate, String actBirthplace) {
        this.idActor = idActor;
        this.actName = actName;
        this.actLastname = actLastname;
        this.actPicture = actPicture;
        this.actBirthdate = actBirthdate;
        this.actBirthplace = actBirthplace;
    }

    public Integer getIdActor() {
        return idActor;
    }

    public void setIdActor(Integer idActor) {
        this.idActor = idActor;
    }

    public String getActName() {
        return actName;
    }

    public void setActName(String actName) {
        this.actName = actName;
    }

    public String getActLastname() {
        return actLastname;
    }

    public void setActLastname(String actLastname) {
        this.actLastname = actLastname;
    }

    public String getActPicture() {
        return actPicture;
    }

    public void setActPicture(String actPicture) {
        this.actPicture = actPicture;
    }

    public Date getActBirthdate() {
        return actBirthdate;
    }

    public void setActBirthdate(Date actBirthdate) {
        this.actBirthdate = actBirthdate;
    }

    public String getActBirthplace() {
        return actBirthplace;
    }

    public void setActBirthplace(String actBirthplace) {
        this.actBirthplace = actBirthplace;
    }

    @XmlTransient
    public Collection<Movie> getMovieCollection() {
        return movieCollection;
    }

    public void setMovieCollection(Collection<Movie> movieCollection) {
        this.movieCollection = movieCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idActor != null ? idActor.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Actor)) {
            return false;
        }
        Actor other = (Actor) object;
        if ((this.idActor == null && other.idActor != null) || (this.idActor != null && !this.idActor.equals(other.idActor))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Actor[ idActor=" + idActor + " ]";
    }
    
}
